﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseComponent;
using System.IO;

public partial class any : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CoursesDB objCoursesDB = new CoursesDB(ConnectionStrings.LMS);
        List<Courses> lstCourses = objCoursesDB.Select("", "");

        lstCourses = new List<Courses>(from obj in lstCourses where obj.objFolder.objMostParent.FolderNameEN.ToLower().Contains("computer") select obj);


        foreach (Courses obj in lstCourses)
        {
            try
            {
                string strName = obj.CourseNameAR;
                if (strName == "")
                    strName = obj.CourseNameEN;

                strName = System.Text.RegularExpressions.Regex.Replace(strName, "[\\\\/:*?\"<>|]", "");

                if (!Directory.Exists(Server.MapPath("CertificateImages/NewFolder")))
                    Directory.CreateDirectory(Server.MapPath("CertificateImages/NewFolder"));


                string strFileName = Server.MapPath("CertificateImages/NewFolder/" + strName + ".zip");
                while (File.Exists(strFileName))
                {
                    strFileName = strFileName + "1.zip";
                }


                File.Copy(Server.MapPath("CoursesFiles/" + obj.Path), strFileName , true);
            }
            catch
            {
            }
        }

    }
}